<admintpl file="header" />
<style>
	em{
		font-style:normal;
		color:#dd2727;
	}

	i{
		font-style:normal;
		padding-left:4px;
	}

	td{
		position: relative;
	}

	td .orderDetail{
		position: absolute;
		display: none;
		background: #fff;
		z-index: 1;
		width:550px;
		top:0;
		left:100%;
		border:1px #ccc solid;
		box-shadow: 0 0 2px #ccc;
		
	}

	.orderDetail span.arrow,.orderDetail span.down{
    height: 24px;
    width: 12px;
    color:#FFF;
    position: absolute;
    top:0;
    left:-6px;
    font-family: 'simsun';
    font-size: 24px;
    overflow: hidden;
    z-index: 10;
	}

	.orderDetail span.down{
	text-shadow: 0 0 2px #ccc;
	color:#ccc;
	left:-7px;
	z-index: 9;
	padding:0;
	
	text-align: left;
	}

	.arrowWrap{
    height:12px ;
    width:6px ;
    position: absolute;
    top:8px;
    left:-6px;
	}

</style>
</head>
<body>
	<div class="wrap js-check-wrap">
		<form class="well form-search" method="post" action="{:U('AdminOrder/index')}">
			订单状态： 
			<select name="status" style="width: 120px;">
				<option value='10000'>全部订单</option>
				<option value="0">未支付订单</option>
				<option value="1">待出库商品</option>
				<option value="3">已出库商品</option>
				<option value="4">已收货商品</option>
				<option value="5">已评价商品</option>
				<option value="6">退货商品</option>
			</select> &nbsp;&nbsp;
			下单时间：
			<input type="text" name="start_time" class="js-datetime" value="{$formget.start_time|default=''}" style="width: 120px;" autocomplete="off">-
			<input type="text" class="js-datetime" name="end_time" value="{$formget.end_time|default=''}" style="width: 120px;" autocomplete="off"> &nbsp; &nbsp;
			订单号/商品关键字： 
			<input type="text" name="keyword" style="width: 200px;" value="{$formget.keyword|default=''}" placeholder="请输入订单号/商品关键字...">
			<input type="submit" class="btn btn-primary" value="搜索" />
			<a class="btn btn-danger" href="{:U('AdminOrder/index')}">清空</a>
		</form>
		<form class="js-ajax-form" action="" method="post">
			<table class="table table-hover table-bordered table-list">
				<thead>
					<tr>
						<th width="15"><label><input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x"></label></th>
						<notempty name="term">
						<th width="50">{:L('SORT')}</th>
						</notempty>
						<th width="50">ID</th>
						<th>{:L('ORDER_SERIAL')}</th>
						<th>{:L('TOTALPRICE')}</th>
						<th>{:L('MODIFY_PRICE')}</th>
						<th width="80">{:L('CONSIGNEE')}</th>
						<th>{:L('TELPHONE')}</th>
						<th width="300">{:L('ADDRESS')}</th>
						<th width="150">{:L('ORDER_TIME')}</th>
						<th width="50">{:L('STATUS')}</th>
						<th width="100">{:L('ACTIONS')}</th>
					</tr>
				</thead>
				<script type="text/javascript">
					//查询模式，用于判断不同查询模式所获取的数据之间一些差异性的数据如何调用
					var queryType='{$queryType}';
					var orderGoodsData={};
					var refund_goods={};
					//查询模式为单件商品时，使用字段数据
					var ExtralData={};
				</script>
				<foreach name="orderData" item="vo">
				<php>
				if($queryType=='orderGoods'){
					$order_id=$vo["order_id"];
				}else if($queryType=='order'){
					$order_id=$vo["order_gid"];
				}
				</php>
				<tr data-id="{$vo.order_gid}">
					<td><input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]" value="{$vo.order_gid}" title="ID:{$vo.order_gid}"></td>
                    <td><b>{$vo.order_gid}</b></td>
					<td>{$vo.order_serial} <a href="javascript:parseOrderGoodsData(orderGoodsData[{$order_id}],{$vo.order_serial},'{$order_id}');">查看订购商品</a><div class="orderDetail" data-serial="{$vo.order_serial}" data-id="{$vo.order_gid}" <if condition="$queryType eq 'orderGoods'">data-orderid="{$vo.order_id}"</if> data-statu="{$vo.status}"></div></td>
					<td><em class="currency">¥</em>
					<em class="totalPrice">
						<if condition="$queryType eq 'order'">
						{$vo.total_price}
						<else />
						{$vo.goods_price}
						</if>
					</em>
					</td>
					<td>
					 <if condition="($vo['modify_price'] eq $vo['total_price']) or ($vo['modify_price'] eq 0)"><span class="modifyPrice">保持原价</span><else /><em class="currency">¥</em> <em class="modifyPrice">{$vo.modify_price}</em></if>
					</td>
					<td>{$vo.consignee}</td>
					<td>{$vo.telphone}</td>
					<td>{$vo.address}</td>
					<td>{:date('Y年m月d日 H:i',strtotime($vo['order_time']))}</td>
					<td>
					<php>
	                  switch($vo['status']){
	                    case 0:
	                    $statuTxt='待付款';
	                    break;
	                    case 1:
	                    $statuTxt=$queryType=='order'?'已付款':'待出库';
	                    break;
	                    case 2:
	                    $statuTxt='已配货';
	                    case 3:
	                    $statuTxt='待收货';
	                    break;
	                    case 4:
	                    $statuTxt='已收货';
	                    break;
	                    case 5:
	                    $statuTxt='已评价';
	                    case 6:
	                    $statuTxt='退货';
	                    break;
	                  }
	                  echo '<em>'.$statuTxt.'</em>';
                  </php>

					</td>
					<td>
						<if condition="$vo['status'] elt 0">
						<a href="javascript:editOrderPrice('{$vo.order_gid}',{$vo.total_price});" class="editOrderPriceBtn">{:L('EDIT_PRICE')}</a> |
						<a href="{:U('AdminOrder/deleteOrder',array('order_id'=>$vo['order_gid'],'deleteType'=>1))}" class="js-ajax-delete " data-subcheck="true" data-msg="您确定要执行删除操作吗？删除后的订单可以在订单回收站找回！<br>注：已经支付的订单只能手动删除！">{:L('DELETE')}</a>
						<else />
							<a href="javascript:void(0);" class="editOrderInfoBtn color-gray" title="已支付的订单无法编辑价格">{:L('EDIT_PRICE')}</a> |
							<a href="javascript:void(0);" class="color-gray" title="已支付的订单无法删除">{:L('DELETE')}</a>
						</if>

					</td>
				</tr>
				<script type="text/javascript">
					orderGoodsData['{$order_id}']='{$vo.goods_data}';
					refund_goods['{$vo.order_serial}']='{$vo.refund_info}';
					if(queryType=='orderGoods'){
						var gid='{$vo.goods_id}-{$vo.sku_idx}';
						var data={};
						data.order_id='{$vo.order_id}';
						data.goods_price='{$vo.goods_price}';
						data.shopBuyNum='{$vo.buy_num}';
						data.logistics_price='{$vo.logistics_price}';
						data.waybill_no='{$vo.waybill_no}';
						data.logistics_wayid='{$vo.logistics_wayid}';
						data.refund_status='{$vo.refund_status}';
						data.refund_info='{$vo.refund_info}';
						ExtralData[gid]=data;						
					}
				</script>
				</foreach>
				<tfoot>
					<tr>
						<th width="15"><label><input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x"></label></th>
						<notempty name="term">
						<th width="50">{:L('SORT')}</th>
						</notempty>
						<th width="50">ID</th>
						<th>{:L('ORDER_SERIAL')}</th>
						<th>{:L('TOTALPRICE')}</th>
						<th>{:L('MODIFY_PRICE')}</th>
						<th width="80">{:L('CONSIGNEE')}</th>
						<th>{:L('TELPHONE')}</th>
						<th width="300">{:L('ADDRESS')}</th>
						<th width="150">{:L('ORDER_TIME')}</th>
						<th width="50">{:L('STATUS')}</th>
						<th width="70">{:L('ACTIONS')}</th>
					</tr>
				</tfoot>
			</table>
			<div class="table-actions">
				<button class="btn btn-danger js-ajax-submit" type="submit" data-action="{:U('AdminOrder/setPrepareBatch')}" data-subcheck="true" data-msg="你确定要将选中订单中所有的商品设置为“完成配货”状态吗？<br>注：未支付的订单以及出库的商品不会被设置！">{:L('SET_PREPARE_STATU')}</button>
				<button class="btn btn-danger js-ajax-submit" type="submit" data-action="{:U('AdminOrder/deleteOrder',array('deleteType'=>1))}" data-subcheck="true" data-msg="您确定要执行删除操作吗？删除后的订单可以在订单回收站找回！<br>注：已经支付的订单需要手动删除！">{:L('DELET_SELECT_ORDRE')}</button>

			</div>
			<div class="pagination">{$page}</div>
		</form>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
	<script src="__PUBLIC__/js/custom/Emall.js"></script>
	<script>
	//当前显示的查看订单商品内容
	var curShowOrderDetail=null;
	//设置配货状态链接
	var postPrepareURL="{:U('AdminOrder/postPrepare')}";
	//设置出库状态链接
	var postDeliveryURL="{:U('AdminOrder/postDelivery')}";
	//编辑保存运单号链接 
	var postEditSerialURL="{:U('AdminOrder/postEditSerial')}";
	//处理退货商品
	var disposeRefundURL="{:U('AdminOrder/disposeRefund')}";
	//删除重置退货单链接（对应的退货信息会被全部清空）
	var deleteRefundURL="{:U('AdminOrder/deleteRefund')}";
	//确认退款
	var postRefundPriceURL="{:U('AdminOrder/postRefundPrice')}"
	//修改订单总金额
	var editOrderPriceURL="{:U('AdminOrder/editOrderPrice')}";
	//ajax加载等待UI
	var loadingContainer=$(window.parent.document).find('body');
	//退货商品的申请信息
	var refund_info={};

	//隐藏订单商品信息
      function closeOrderDetail(){
      	curShowOrderDetail.hide();
      	curShowOrderDetail=null;
      }

      //隐藏退货信息
      function closeRefundDetail(gid){
      	var refundInfoWrap=$('.orderDetail dd[data-gid="'+gid+'"]');
      	refundInfoWrap.find('.refundInfo').hide();
      	refundInfoWrap.find('.disposeRefundBtn').show();
      }

      //处理退货商品
      function disposeRefund(gid,order_id,refund_status){
      	var refundData=queryType=='order'?refund_info[gid]:$.parseJSON(ExtralData[gid].refund_info);
      	//显示退货信息
      	var refundInfoWrap=$('.orderDetail dd[data-gid="'+gid+'"]');
      	var refundInfo=refundInfoWrap.find('.refundInfo');
      	var actionBtnHTML='';
      	//判断信息容器是否存在，不存在则添加
      	if(refundInfo.length==0){       		
  				actionBtnHTML=updateRefundOptionUI(gid,order_id,refund_status);
  				//显示退货信息
  				refundWayBillNo=refundData.refundWayBillNo?'退货运单号：<em>'+refundData.refundWayBillNo+'</em>':'';
  				refundInfo=$(
  					'<div class="refundInfo"><p>联系人：<em>'+refundData.contact+'</em>联系电话：<em>'+refundData.telNum+'</em>'+refundWayBillNo+'</p><p>退货详细说明：'+refundData.detail+'</p>'
  					+actionBtnHTML
  					).appendTo(refundInfoWrap);
      	}else{
      		refundInfo.show();
      	}
      	//隐藏展开退货信息的按钮
      	refundInfoWrap.find('.disposeRefundBtn').hide();
      }

      //删除重置退货单（对应的退货信息会被全部清空）
      function deleteRefund(order_id,gid){
      		messagesBox({
      			title:'删除重置退货单',
      			content:'此操作将删除当前操作订单商品的对应退货申请信息！删除后将无法还原，您确认要执行此操作吗？',
      			frameShow:false,
      			callFunc:function(){
      				postRefundDispose(0,order_id,gid);
      			}
      		})
      }

      //提交退货处理数据（disposeType=0为清空重置退货信息，1为同意退货，2为拒绝退货，3为确认收货）
      function postRefundDispose(disposeType,order_id,gid){
      		var refundInfoWrap=$('.orderDetail dd[data-gid="'+gid+'"]');
      		var disposeDetail=refundInfoWrap.find('textarea').val();
      		if(disposeType>0 && disposeType<=2){
      			if(disposeDetail==''){
      				alert('请先输入退货操作详情说明！');
      				return false;
      			}
			}
			$('body').setLoadingState({container:'body',loadingTxt:'正在提交退货处理数据，请稍候...'})
  			$.post(disposeRefundURL,{order_id:order_id,gid:gid,disposeType:disposeType,disposeDetail:disposeDetail},function(data){
  				if(data.status==1){
  					var refundStatus=disposeType==2?-1:disposeType;
  					var actionBtnHTML=updateRefundOptionUI(gid,order_id,refundStatus);      					

  					refundInfoWrap.find('.refundInfo').queue(function(next){
  						$(this).find('.refundBottomBar').remove();
  						$(this).next();
  					}).append(actionBtnHTML);

  				}else{
  					alert(data.error);
  				}
  				$('body').setLoadingState('destroy');
  				console.log(data);
  			}).error(function(){
  				alert('链接服务器出错，无法提交退货处理数据,请稍候尝试！');
  				$('body').setLoadingState('destroy');
  			})
      		
      }

      //确认退款操作
      function postRefundPrice(order_id,gid){
      		var refundInfoWrap=$('.orderDetail dd[data-gid="'+gid+'"]');

      		var goods_price=parseFloat(refundInfoWrap.find('.goodsPrice').text());
      		var deductPrice=refundInfoWrap.find('.refundPrice').val();
      		var refundPrice=goods_price-parseFloat(deductPrice);

      		if(deductPrice==''){
      			alert('请填写需要扣除的金额，再确认退款！');
      			return false;
      		}

      		messagesBox({
      			title:'确认退款',
      			content:'您正在执行退款操作：扣除金额 <em class="currency">¥</em> <em>'+Number(deductPrice).toFixed(2)+'</em>，总计退款金额为 <em>¥</em> <em>'+Number(refundPrice).toFixed(2)+'</em><br>您确定要退款吗？',
      			frameShow:false,
      			callFunc:function(){
		      		$('body').setLoadingState({container:'body',loadingTxt:'正在执行退款操作，请稍候...'});
		      		$.post(postRefundPriceURL,{order_id:order_id,gid:gid,deductPrice:deductPrice},function(data){      
		      			console.log(data);	
		      			if(data.status==1){
		      				//移除退款操作元素
		      				refundInfoWrap.find('.refundBottomBar .confirmRefundPrice').remove();
		      				refundInfoWrap.find('.refundBottomBar .refundPrice').remove();
		      				refundInfoWrap.find('.refundBottomBar .currency').remove();
		      				refundInfoWrap.find('.disposeRefundBtn').text('完成退货');
		      				refundInfoWrap.find('.applyRefund').text('完成退货');
		      				//隐藏运单号编辑链接
		      				refundInfoWrap.closest('dl').find('dt .edit-right').hide();
		      			}else{
		      				alert(data.error);
		      			}
		      			$('body').setLoadingState('destroy');
		      		}).error(function(){
		      			alert('链接服务器错误，无法执行退款操作，请稍候尝试！');
		      			$('body').setLoadingState('destroy');
		      		})	
      			}
      		});
      }

      //编辑订单总金额
      function editOrderPrice(order_id,orderPrice){
      	var editHtml='<p style="text-align:center">原订单总金额：<em class="currency">¥</em> <em class="totalPrice">'+Number(orderPrice).toFixed(2)+'</em></p>'
      				+'<p style="text-align:center">- ¥ <input type="text" id="input_editPrice" class="price" placeholder="请输入减免的金额"></p>'
      				+'<p style="text-align:center">修改后的订单总金额：<em class="currency">¥</em> <em class="modifyPrice">'+Number(orderPrice).toFixed(2)+'</em></p>';
       		var ModalDialog=$('#myModal');

       		messagesBox({
      			title:'修改订单总金额',
      			content:editHtml,
      			frameShow:false,
      			callFunc:function(){
      				var priceInput=$('#input_editPrice');
      				var deductPrice=priceInput.val();
      				if(deductPrice=='' || !deductPrice){
      					return false;
      				}

		      		$('body').setLoadingState({container:'body',loadingTxt:'正在提交修改的订单总金额，请稍候...'});
		      		$.post(editOrderPriceURL,{order_id:order_id,deductPrice:deductPrice},function(data){      
		      			console.log(data);	
		      			if(data.status==1){
		      				//生成修改价格的html
		      				var modifyPriceHtml=Number(orderPrice)==Number(data.data.modify_price) || !data.data.modify_price?'<span class="modifyPrice">保持原价</span>'
		      				:'<em class="currency">¥</em> <em class="modifyPrice">'+Number(data.data.modify_price).toFixed(2)+'</em>';
		      				$('tr[data-id="'+order_id+'"] .modifyPrice').closest('td').html(modifyPriceHtml);
		      			}else{
		      				alert(data.error);
		      			}
		      			$('body').setLoadingState('destroy');
		      		}).error(function(){
		      			alert('链接服务器错误，无法提交修改的订单数据，请稍候尝试！');
		      			$('body').setLoadingState('destroy');
		      		})	
      			}
      		}); 


      		//绑定修改金额事件
      		if(ModalDialog.length==0){      			
	      		$('#input_editPrice').on('keyup',function(){
	      			var deductPrice=parseFloat($(this).val());
	      			if(isNaN(deductPrice)){
	      				deductPrice=0;
	      			}
	      			var modalContent=$(this).closest('.modal-body');
	      			var totalPrice=parseFloat(modalContent.find('.totalPrice').text());
	      			modalContent.find('.modifyPrice').text(Number(totalPrice-deductPrice).toFixed(2));
	      		})
      		}
      }

      //刷新退货处理操作界面元素
      function updateRefundOptionUI(gid,order_id,status){
      	var actionBtnHTML='';
		//操作按钮代码生成（当退货处于申请状态时有三个操作按钮，进入正式退货流程后只有确认收货按钮和确认退款按钮）
		var cancelBtn='<a class="orderBtn bg-gray" href="javascript:closeRefundDetail(\''+gid+'\')">取消退出</a>';
		if(status==0){
			//清除所有的退货状态和信息数据
				var clearRefundGoods=$('.orderDetail dd[data-gid="'+gid+'"]');
				 clearRefundGoods.find('.refundInfo').remove();
				 clearRefundGoods.find('.itemImg .applyRefund').remove();
		}else if(status==1){
			actionBtnHTML='<div class="refundBottomBar"><p>退货处理详细说明：</p><textarea placeholder="请输入退款金额/拒绝退货理由/其它说明等"></textarea><a class="orderBtn bg-blue setDelivery" href="javascript:postRefundDispose(-1,\''+order_id+'\',\''+gid+'\');">拒绝退货</a><a class="orderBtn bg-blue setDelivery" href="javascript:postRefundDispose(2,\''+order_id+'\',\''+gid+'\');">同意退货</a>'+cancelBtn+'</div></div>';
		}else if(status==2 || status==-1){
				actionBtnHTML='<div class="refundBottomBar"><a class="orderBtn bg-blue deleteRefund" href="javascript:deleteRefund(\''+order_id+'\',\''+gid+'\')">删除重置</a>'
				//+'<a class="orderBtn bg-blue setPrepare" href="javascript:postRefundDispose(4,\''+order_id+'\',\''+gid+'\');">确认收货</a>'
				+cancelBtn+'</div></div>';
		}else if(status==3){
			actionBtnHTML='<div class="refundBottomBar"><a class="orderBtn bg-blue confirmReveivedGoods" href="javascript:postRefundDispose(4,\''+order_id+'\',\''+gid+'\');">确认收货</a>'+cancelBtn+'</div></div>';
		}else if(status==4){
			actionBtnHTML='<div class="refundBottomBar"><em class="currency">¥</em><input type="text" class="refundPrice" placeholder="请填写需要扣除的金额"><a class="orderBtn bg-blue confirmRefundPrice" href="javascript:postRefundPrice(\''+order_id+'\',\''+gid+'\');">确认退款</a>'+cancelBtn+'</div></div>';
		}else if(status==5){
			actionBtnHTML='<div class="refundBottomBar">'+cancelBtn+'</div></div>';
		}
		return actionBtnHTML;
      }

		function refersh_window() {
			var refersh_time = getCookie('refersh_time');
			if (refersh_time == 1) {
				window.location = "{:U('AdminOrder/index',$formget)}";
			}
		}

		setInterval(function() {
			refersh_window();
		}, 2000);

		  var orderStatuCode='<em class="orderStatu-normal">配货中</em>以下订单商品等待配货';
		  var waybillDetailURL='http://api.logistics.com/';

		  //状态码文本转换
		  function getStatusText(status){
		    var statuTxt;
		    switch(parseInt(status)){
		      case 0:
		      statuTxt='待付款';
		      break;
		      case 1:
		      statuTxt='待出库';
		      break;
		      case 2:
		      statuTxt='已配货';
		      break;
		      case 3:
		      statuTxt='待收货';
		      break;
		      case 4:
		      statuTxt='已收货';
		      break;
		      case 5:
		      statuTxt='已评价';
		      break;

		    }
		    return statuTxt;
		  }

		  //解析订单商品数据到订单内容容器中,order_id为order_relationships表中的order_id， 用于单件商品查询模式
		  function parseOrderGoodsData(goodsData,order_serial,order_id){
		    if(!goodsData){
		      return false;
		    }

		      var result=$.parseJSON(goodsData);

		      var orderGoodsHTML='';
		      var deliveryGoodsHTML='';
		      var prepareGoodsHTML='';
		      var goodsItemWrap=queryType=='order'?$('.orderDetail[data-serial="'+order_serial+'"]'):$('.orderDetail[data-orderid="'+order_id+'"]');
		      var order_id=goodsItemWrap.attr('data-id');

		      if(goodsItemWrap.text()==''){
			      goodsItemWrap.append('<div class="arrowWrap"><span class="arrow">◆</span><span class="down">◆</span></div>').show();
			      if(curShowOrderDetail){
			      	curShowOrderDetail.hide();
			      }
			      curShowOrderDetail=goodsItemWrap;
		      }else{
			      if(curShowOrderDetail){
			      	curShowOrderDetail.hide();
			      }
			      curShowOrderDetail=goodsItemWrap;
		      	  goodsItemWrap.show();
		      	  return false;
		      }

		      
	           //添加绑定编辑保存运单号事件
	           function bindEidtEvnt(titleBar){
	               titleBar.find('.edit-right').on('click',function(){
	               		var $this=$(this);
	               		var serial=titleBar.find('.serial');
		               	var editText=$this.text();
		               	var oldSerial=serial.text();

	               		if(editText=='编辑运单号'){
		               		serial.append('<input type="text" value="'+serial.text()+'">');
	               			$this.text('保存编辑')
	               		}else{
	               			$this.text('编辑运单号');
	               			var newSerial=serial.find('input').val()
	               			if(newSerial==oldSerial){
	           					serial.find('input').remove();
	           					serial.text(newSerial);
	           					$this.text('编辑运单号');
	               				return false;
	               			}
	               			//提交编辑数据
	               			$.post(postEditSerialURL,{waybill_no:newSerial,oldSerial:oldSerial,order_id:order_id},function(data){
	               				if(data.status==1){
	               					serial.find('input').remove();
	               					serial.text(newSerial);
	               					$this.text('编辑运单号');
	               				}else{
	               					alert(data.error);
	               				}
	               			}).error(function(){
	               				alert('链接服务器出错，无法提交数据,请稍候尝试！');
	               			})
	               		}
	               		
	               })		               	
	           }

	           //生成订单商品html代码
	           function makeGoodsListHTML(gid,Item,status){
                //按长度要求截取标题字符
                var sliceLength=Item.goods_title.length<32?Item.goods_title.length:32;
                var goods_title=Item.goods_title.substr(0,sliceLength);
                goods_title+=Item.goods_title.length>32?'...':'';

                //判断是否需要禁用复选框
                checkEnable=status>0 && status<4 ?true:false;
                var orderChecked=queryType=='orderGoods'?'checked':'';
                var goods_id=queryType=='orderGoods'?ExtralData[gid].goods_id:Item.goods_id;
                var goods_price=queryType=='orderGoods'?ExtralData[gid].goods_price:Item.price;
                var shopBuyNum=queryType=='orderGoods'?ExtralData[gid].shopBuyNum:Item.shopBuyNum;
                var logistics_price=queryType=='orderGoods'?ExtralData[gid].logistics_price:Item.logistics_price;
                var logistics=queryType=='orderGoods'?ExtralData[gid].logistics_wayid:Item.logistics;
                var refund_status=queryType=='orderGoods'?parseInt(ExtralData[gid].refund_status):parseInt(Item.refund_status);

                //退货处理UI元素HTML
                var imgRefundTag='';
                var refundActionBtnHtml='';
                var refundTag='申请退货';
	            var controlTag='处理退货';
	            if( !isNaN(refund_status) && refund_status!==0){
		            if(refund_status==-1){
		            	controlTag=refundTag='拒绝退货';
		            }else if(refund_status==5){
		            	controlTag=refundTag='完成退货';
			            //完成退货后隐藏运单编辑
			            //goodsItem.closest('dl').find('dt .edit-right').hide();
		            }
			           
		            imgRefundTag='<em class="applyRefund">'+refundTag+'</em>';

		            //添加退货处理按钮
		            refundActionBtnHtml='<a class="orderBtn bg-red disposeRefundBtn" target="_blank" href="javascript:disposeRefund(\''+gid+'\',\''+order_id+'\','+refund_status+')">'+controlTag+'</a>';
		        }

	           	var checkboxHTML=checkEnable?'<div style="width:6%"><input type="checkbox" data-name="orderList" '+orderChecked+'></div>':'';
	           	var canBuyTag=Item.shopBuyNum==0?'<em class="outOfStock">已售罄</em>':'';
	           	var HTMLCode='<dd data-gid="'+gid+'">'+checkboxHTML+'<div class="itemImg fixImgPadding">'
		                                +'<a href=""><img src="'+Item.goods_img+'" width="80" class="cartGoodsImg" alt=""></a>'+canBuyTag+imgRefundTag+'</div>'
		                                +'<div class="listInfo"><p><a href="{:U(\'EMall/GoodsDetails/index\')}'+'&id='+goods_id+'" target="_blank">'+goods_title+'</a></p>'
		                                +'<p>'+Item.sku_style+' '+Item.sku_spec+'</p>'
			                            +'<p><em>¥</em> <em class="goodsPrice">'+Number(goods_price).toFixed(2)+'</em> X '+shopBuyNum
			                            +'&nbsp;&nbsp;&nbsp;&nbsp;运费：<em>¥</em> <em>'+Number(logistics_price).toFixed(2)+'</em>&nbsp;&nbsp;&nbsp;&nbsp;配送方式：<em>'+changeToLogistaticsStr(logistics)+'</em></p></div>'+refundActionBtnHtml+'</dd>';
			    	return HTMLCode;
	           }

	           console.log(result);
	           //出库商品数
	           var shipGoodsNum=0;
	           //完成配货的商品数
	           var prepareGoodsNum=0;


	           $.each(result,function(gid,Item){
	           		var goods_status;
	           		if(queryType=='order'){
	           			goods_status=parseFloat(Item.status);
	           			refund_info[gid]=Item.refund_info;
	           		}else if(queryType=='orderGoods'){
	           			goods_status=goodsItemWrap.attr('data-statu');
	           		}
	           		//出库商品，如果出库商品的运单号一样，则输出商品到同组容器中
	           		if(goods_status >=3){
	           			var deliveryGoodsHTML=makeGoodsListHTML(gid,Item,goods_status);
	           			shipGoodsNum++;
						var editHTML=goods_status<4?'<a href="javascript:void(0);" class="edit-right">编辑运单号</a>':'';
						var sameContainer=goodsItemWrap.find('dl[data-serial="'+Item.waybill_no+'"]');
						var statuTxt=goods_status>3?'已收货':'已出库';
						var waybill_no=queryType=='orderGoods'?ExtralData[gid].waybill_no:Item.waybill_no;

						if(sameContainer.length>0){
							sameContainer.append(deliveryGoodsHTML);
						}else{
							var titleBar= $('<dl data-statu="delivery" data-serial="'+waybill_no+'"><dt><em class="orderStatu-normal bg-green">'+statuTxt+'</em>物流公司：'+Item.company+' 运单号：<i class="serial">'+waybill_no+'</i>'+editHTML+'</dt>'+deliveryGoodsHTML+'</dl>').prependTo(goodsItemWrap);
							//确认收货后不再绑定事件
							if(goods_status<4){
	            				bindEidtEvnt(titleBar);
	            			}
						}
						
		            //已完成配货的商品
	           		}else if(goods_status==2){
	           			var prepareGoodsHTML=makeGoodsListHTML(gid,Item,goods_status); 		                
		                prepareGoodsNum++;
		                var sameContainer=goodsItemWrap.find('dl[data-statu="prepare"]');

		                if(sameContainer.length>0){
							sameContainer.append(prepareGoodsHTML);
						}else{							
		                	goodsItemWrap.append('<dl data-statu="prepare"><dt><em class="orderStatu-normal">已配货</em>以下订单商品等待出库</dt>'+prepareGoodsHTML+'</dl>');
						}
					//未完成配货的商品
	           		}else if(goods_status==1 || goods_status==0){
	           			var orderGoodsHTML=makeGoodsListHTML(gid,Item,goods_status);
	           			var sameContainer=goodsItemWrap.find('dl[data-statu="normal"]');

		                if(sameContainer.length>0){
							sameContainer.append(orderGoodsHTML);
						}else{
	           				goodsItemWrap.append('<dl data-statu="normal"><dt><em class="orderStatu-normal">配货中</em>以下订单商品等待配货</dt>'+orderGoodsHTML +'</dl>');  
						}
	           		}
	           })

		     

	      	//查看订单商品信息的操作设置栏代码（已付款的订单才能被操作）
	      	var orderStatu=goodsItemWrap.attr('data-statu');
	      	var bottomBarHTML=orderStatu>0?'<div class="bottomBar"><a class="orderBtn bg-red setPrepare" href="javascript:void(0);">设置配货</a><a class="orderBtn bg-red setDelivery" href="javascript:void(0);">设置出库</a><a class="orderBtn bg-gray" href="javascript:closeOrderDetail()">取消退出</a></div>':'<div class="bottomBar"><a class="orderBtn bg-gray" href="javascript:closeOrderDetail()">取消退出</a></div>';

		      
		      goodsItemWrap.append(bottomBarHTML); 


		      //绑定操作按钮事件
		      //设置商品为已经完成配货的状态
		    goodsItemWrap.find('.setPrepare').on('click',function(){
		      	var gidGroup='';
		      	var changeGID='';		//此gid字串用于更改已经出库的商品到配货完成状态
		      	var prepareAll=0;		//用于标识当前商品是否全部完成配货
		      	var setGoodsItem=goodsItemWrap.find('dl:not([data-statu="prepare"]) :checkbox[data-name="orderList"]:checked');
		      	if(setGoodsItem.length<=0){
		      		alert('请至少选择一件非配货完成状态的商品！');
		      		return false;
		      	}

		      	
		      	loadingContainer.setLoadingState({container:'body',loadingTxt:'正在设置配货状态，请稍等...'});
		      	//生成gidGroup字串
		      	$.each(setGoodsItem,function(){
		      		var gid = $(this).closest('dd').attr('data-gid');
		      		gidGroup+=gidGroup!==''?','+gid:gid;

		      	})
		      	

		      	//判断更新后，是否所有商品都处于完成配货状态（通过获取未配货容器是否存在或者其中所有商品是否被勾选设置来判断）
		      	var normalGoodsItem=goodsItemWrap.find('dl[data-statu="normal"] dd');
		      	if(normalGoodsItem.length>0){
		      		if(normalGoodsItem.find(':checkbox:checked').length==normalGoodsItem.length){
		      			prepareAll=1;
		      		}
		      	}else{
		      		prepareAll=1;
		      	}

		      	//提交设置配货数据
		      	$.post(postPrepareURL,{gidGroup:gidGroup,order_id:order_id,prepareAll:prepareAll},function(data){
		      		//console.log(gidGroup+'|'+changeGID);
		      		if(data.status==1){
		      			var prepareContent;
		      			//判断是否已经存在配货完成的商品,不存在则先直接按位置插入容器
		      			if(goodsItemWrap.find('dl[data-statu="prepare"]').length==0){
		      				var normalGoodsItem=goodsItemWrap.find('dl[data-statu="normal"]');
		      				var deliveryGoodsItem=goodsItemWrap.find('dl[data-statu="delivery"]:last');
		      				var wrapHTML='<dl data-statu="prepare"><dt><em class="orderStatu-normal">已配货</em>等待商品出库</dt></dl>';
		      				//存在未配货商品时插入到其前
		      				if(normalGoodsItem.length>0){
		      					normalGoodsItem.before(wrapHTML);
		      				//存在出库商品时插入到其后
		      				}else if(deliveryGoodsItem.length>0){
		      					deliveryGoodsItem.after(wrapHTML);
		      				//否则直接插入
		      				}else{
		      					goodsItemWrap.prepend(wrapHTML);
		      				}
		      			}
		      			prepareContent=goodsItemWrap.find('dl[data-statu="prepare"]');

		      			//将原商品复制到已配货的商品列表中后删除
		      			$.each(setGoodsItem,function(){
		      				var goodsItem=$(this).closest('dd');
		      				//取消勾选checkbox
		      				goodsItem.clone(true).appendTo(prepareContent).find(':checkbox').prop('checked',false);
		      				goodsItem.remove();
		      				prepareGoodsNum++;
		      			})
		      			//如果所有商品都已经完成配货则移除其容器
		      			var normalGoodsItem=goodsItemWrap.find('dl[data-statu="normal"]');
		      			if(normalGoodsItem.find('dd').length==0){
		      				normalGoodsItem.remove();
		      			}
		      			//如果包含从出库状态转换到配货状态的商品，循环判断所有出库容器是否需要清除
	      				$.each(goodsItemWrap.find('dl[data-statu="delivery"]'),function(){
	      					if($(this).find('dd').length==0){
	      						$(this).remove();
	      					}
	      				})

		      			alert('设置商品配货成功！');
		      		}else{
		      			alert(data.error);
		      		}
		      		loadingContainer.setLoadingState('destroy');
		      	}).error(function(data){
		      		alert('链接服务器出错，无法提交数据,请稍候尝试！');
		      		loadingContainer.setLoadingState('destroy');
		      	})
		    })


		    //设置出库事件绑定  
			goodsItemWrap.find('.setDelivery').on('click',function(){
		      	var setGoodsItem=goodsItemWrap.find('dl:not([data-statu="delivery"]) :checkbox[data-name="orderList"]:checked');
		      	if(setGoodsItem.length<=0){
		      		alert('请至少选择一件未出库的商品！');
		      		return false;
		      	}
		      	var bottomBar=goodsItemWrap.find('.bottomBar');
		      	//生成出库运单号设置界面
		      	var setWayBill=goodsItemWrap.find('.setWayBill');
		      	if(setWayBill.length==0){
			      	//添加运单号的HTML
			      	bottomBar.before('<div class="setWayBill">输入运单号：<input type="text" value="" id="waybill_no"><a href="javascript:void(0);" class="orderBtn bg-blue postDelivery">确认出库</a><a href="javascript:void(0);" class="orderBtn bg-gray cancelSet">取消设置</a></div>');
			      	setWayBill=goodsItemWrap.find('.setWayBill');

			      	//取消出库设置事件
			      	setWayBill.find('.cancelSet').on('click',function(){	
			      		setWayBill.hide();
			      	})

			      	//提交出库数据事件
			      	setWayBill.find('.postDelivery').on('click',function(){
				      	var setGoodsItem=goodsItemWrap.find('dl:not([data-statu="delivery"]) :checkbox[data-name="orderList"]:checked');
				      	if(setGoodsItem.length<=0){
				      		alert('请至少选择一件未出库的商品！');
				      		return false;
				      	}

				      	var gidGroup='';
				      	var prepare_gid='';
				      	var shipAll=0;			//判断是否已经全部出库的标识（用于保存数据时判断是否需要更新状态数据）
				      	var prepareAll=0;
				      	//生成gidGroup字串
				      	$.each(setGoodsItem,function(){
				      		var gid=$(this).closest('dd').attr('data-gid');
				      		gidGroup+=gidGroup!==''?','+gid:gid;
				      	})
				      	//如果当前商品已经全部出库则将配货商品字段数据清零,否则更新设置出库后的配货商品
				      	var shipGoodsItem=goodsItemWrap.find('dl[data-statu="delivery"] dd');
				      	if((shipGoodsItem.length+setGoodsItem.length)!==Object.keys(result).length){		      		
				      		var prepareGoodsItem=goodsItemWrap.find('dl[data-statu="prepare"] :checkbox[data-name="orderList"]:checked');
				      		prepareGoodsNum=prepareGoodsItem.length;
				      		//生成配货商品gid字串
					      	$.each(prepareGoodsItem,function(){
					      		var gid=$(this).closest('dd').attr('data-gid');
					      		prepare_gid+=prepare_gid!==''?','+gid:gid;			      		
					      	})
				      	}else{
				      		prepare_gid='';
				      		shipAll=1;
				      	}

				      	//console.log(shipGoodsItem+'|'+orderGoodsNum);

				      	//判断更新后，是否所有商品都处于完成配货状态（通过获取未配货容器是否存在或者其中所有商品是否被勾选设置来判断）
				      	var normalGoodsItem=goodsItemWrap.find('dl[data-statu="normal"] dd');
				      	if(normalGoodsItem.length>0){
				      		if(normalGoodsItem.find(':checkbox:checked').length==normalGoodsItem.length){
				      			prepareAll=1;
				      		}
				      	}else{
				      		prepareAll=1;
				      	}

			      		//获取设置出库的运单号
			      		var set_waybill_no=setWayBill.find('#waybill_no').val();
			      		//console.log(set_waybill_no+'|'+prepare_gid+'|'+order_id+'|'+gidGroup);
			      		
			      		$('body').setLoadingState({container:'body',loadingTxt:'正在设置配货状态，请稍等...'});
			      		//提交数据到服务器
				      	$.post(postDeliveryURL,{
					      		gidGroup:gidGroup,
					      		waybill_no:set_waybill_no,
					      		prepare_gid:prepare_gid,
					      		order_id:order_id,
					      		shipAll:shipAll,
					      		prepareAll:prepareAll
				      		},
				      		function(data){
					      		if(data.status==1){
					      			//判断是否是后继合并出库设置商品到已经存在的运单中
					      			var deliveryContent=goodsItemWrap.find('dl[data-serial="'+set_waybill_no+'"]');
					      			if(deliveryContent.length==0){
					      				deliveryContent=$('<dl data-statu="delivery" data-serial="'+set_waybill_no+'"><dt><em class="orderStatu-normal bg-green">已出库</em>物流公司：'+' 运单号：<i class="serial">'+set_waybill_no+'</i><a href="javascript:void(0);" class="edit-right">编辑运单号</a></dt></dl>').prependTo(goodsItemWrap);

					      				bindEidtEvnt(deliveryContent.find('dt'));
					      			}
					      			//将原商品复制到已出库的商品列表中后删除
					      			$.each(setGoodsItem,function(){
					      				var goodsItem=$(this).closest('dd');
					      				//取消checkbox勾选
					      				goodsItem.clone(true).appendTo(deliveryContent).find(':checkbox').prop('checked',false);
					      				goodsItem.remove();
					      				shipGoodsNum++;
					      			})

				      				var normalGoodsItem=goodsItemWrap.find('dl[data-statu="normal"]');
				      				var prepareGoodsItem=goodsItemWrap.find('dl[data-statu="prepare"]');
				      				if(normalGoodsItem.find('dd').length==0){
				      					goodsItemWrap.find('dl[data-statu="normal"]').remove();
				      				}
				      				if(prepareGoodsItem.find('dd').length==0){
				      					goodsItemWrap.find('dl[data-statu="prepare"]').remove();
				      				}

					      			alert('设置出库成功！');
					      		}else{
					      			alert(data.error);
					      		}

					      		$('body').setLoadingState('destroy');
				      	}).error(function(){
				      		alert('链接服务器出错，无法提交数据,请稍候尝试！');
				      		$('body').setLoadingState('destroy');
				      	})		      		
			      	})

		      	}else{
		      		setWayBill.show();
		      	}

			})

			//定位订单信息容器
	      	var offsetTop=curShowOrderDetail.closest('tr').offset().top;
			$(window).scroll(function(){
				offsetTop=offsetTop-$(this).scrollTop();
				//console.log($(this).scrollTop());
			})

	      	var bodyHeight=$('body').height();
	      	var offsetHeight=curShowOrderDetail.outerHeight();

	      	if(offsetTop>bodyHeight/2){
	      		if(offsetHeight>offsetTop || offsetHeight>bodyHeight/2){
		      		curShowOrderDetail.css({'top':18-offsetHeight/2,'left':'100%'});
		      		goodsItemWrap.find('.arrowWrap').css({'top':offsetHeight/2-10});
	      		}else if(offsetHeight/2<offsetTop){
		      		curShowOrderDetail.css({'top':36-offsetHeight,'left':'100%'});
		      		goodsItemWrap.find('.arrowWrap').css({'top':offsetHeight-28});
	      		}
	      	}else{
	      		if(bodyHeight-offsetTop<offsetHeight || bodyHeight<offsetHeight){
		      		curShowOrderDetail.css({'top':0-offsetTop,'left':'100%'});
		      		goodsItemWrap.find('.arrowWrap').css({'top':8+offsetTop});		      			
	      		}else if(offsetHeight/2>offsetTop ){
		      		curShowOrderDetail.css({'top':18-offsetHeight/2,'left':'100%'});
		      		goodsItemWrap.find('.arrowWrap').css({'top':offsetHeight/2-10});
	      		}
	      	}

		      //console.log(goodsData);
		  }

		function changeToLogistaticsStr($idx){
		    $wayStr='';
		        switch(parseInt($idx)){
		            case 0:
		                $wayStr='快递';
		                break;
		            case 1:
		                $wayStr='物流';
		                break;
		            case 2:
		                $wayStr='EMS';
		                break;
		            case 3:
		                $wayStr='平邮';
		                break;
		        }
		    return $wayStr;
		}


		 /*/删除订单(ajax暂时无用)
		function deleteOrder(order_id,deleteType,returnType){
			if(order_id && order_id!==''){
				if(returnType=='ajax'){
					$('body').setLoadingState({container:'body',loadingTxt:'正在执行删除订单操作，请稍候...'});
					$.post(deleteOrderURL,{order_id:order_id,deleteType:deleteType},function(data){
						if(data.status==1){

						}else{
							alert(data.error);
						}
						$('body').setLoadingState('destroy');
					}).error(function(){
						alert('链接服务器出错，无法删除订单,请稍候尝试！');
						$('body').setLoadingState('destroy');
					})
				}else{
					$(window).location.href(deleteOrderURL);
				}
			}
		}*/

		$(function(){


		})
	</script>
</body>
</html>